#include "EpilIndexParser.h"
#include "EpilParserException.h"
#include "EpilExpressionParser.h"
#include "EpilPointerHelper.h"


EpilIndexParser::EpilIndexParser( EpilTokenStream & tokens )
: EpilSyntaxParserBase( tokens )
{
}


void EpilIndexParser::Parse()
{
	// index -> '[' expr ']'
	this->GetTokens().MoveToNext();

	EpilExpressionParser exprParser( this->GetTokens() );
	exprParser.Parse();

	m_indexExpression = exprParser.GetExpression();

	if( this->GetTokens().GetCurrentToken().type != ETT_CloseBracket )
	{
		EpilPointerHelper::SafeDelete( m_indexExpression );
		throw EpilParserException( t("\'[\' expected."), this->GetTokens().GetCurrentToken().location );
	}
	this->GetTokens().MoveToNext();
}